package mn.buya.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * Датабаз үүсгэх класс
 * 
 * @author mbms
 * @version 1.0
 * 
 */
public class AppDataHelper extends SQLiteOpenHelper {

	/**
	 * Датабаз-ын нэр
	 */
	private static final String DATABASE_NAME = "mydb";
	private static final int DATABASE_VERSION = 1;

	/**
	 * Үндсэн хүснэгтийн нэр
	 */
	public static final String TABLE_NAME = "question_answer";

	/**
	 * Хүснэгт үүсгэх асуулга
	 */
	private static final String TABLE_CREATE_QUERY = "CREATE TABLE "
			+ TABLE_NAME + " (_id INTEGER PRIMARY KEY AUTOINCREMENT,"
			+ " question TEXT NOT NULL, answer TEXT NOT NULL);";

	public AppDataHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(TABLE_CREATE_QUERY);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(AppDataHelper.class.getName(), "Upgrading database from version "
				+ oldVersion + " to " + newVersion
				+ ", which will destroy all old data");

		db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);

		onCreate(db);
	}

}
